package com.test1230pm;

import com.java1228.S;

public class Test04 {
    public static void main(String[] args) {
        // (4)设计一个学生类和学校类
        // 场景：学生王五在大连科技上学、学生赵六在大连大学上学
        // 要求：根据需求创建学生和学校对象、并能表示出学生和学校之间的关联关系、打印学生以及所在学校的信息
        School s1 = new School("大连科技");
        Student m1  = new Student("王五",18,s1);
        m1.print();
        System.out.println(m1.toString());


        School s2 = new School("大连大学");
        Student m2  = new Student("赵六",20,s2);
        m2.print();
        System.out.println(m2.toString());
    }
}
class School{
    private String S_name;

    public School(String s_name) {
        S_name = s_name;
    }

    public String getS_name() {
        return S_name;
    }

    public void setS_name(String s_name) {
        S_name = s_name;
    }

    @Override
    public String toString() {
        return S_name ;

    }
}
class Student{
    private String name;
    private int age;
    private School school;

    public Student(String name, int age, School school) {
        this.name = name;
        this.age = age;
        this.school = school;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public School getSchool() {
        return school;
    }

    public void setSchool(School school) {
        this.school = school;
    }
    public void print(){
        System.out.println("学生"+name+"在"+school.getS_name()+"上学");
    }

    @Override
    public String toString() {
        return
                "学生姓名：" + name +
                "学生年龄：" + age +
                "学校：" + school ;

    }
}